package Rmq

import (
	managerDao "deepgox-go-admin/Dao/RmqManager"
	managerModels "deepgox-go-admin/Models/Manager"
	"deepgox-go-admin/Pkg/HttpResponse"
	"deepgox-go-admin/Pkg/Util"
	"github.com/gin-gonic/gin"
	"strconv"
)

func RmqAddManager(c *gin.Context) {
	p := new(managerModels.AddModelHandler)
	if err := c.ShouldBindJSON(&p); err != nil {
		HttpResponse.ResponseErrorWithMsg(c, HttpResponse.CodeInvalidParams, "参数格式错误")
		return
	}
	if len(p.UserName) == 0 || len(strconv.FormatInt(p.Gender, 36)) == 0 || len(p.Password) == 0 {
		//请求参数有误
		HttpResponse.ResponseErrorWithMsg(c, HttpResponse.CodeInvalidParams, "参数不能为空")
		return
	}
	PW := Util.MD5(p.Password)
	manager := &managerDao.RegModelHandler{managerModels.AddModelHandler{
		UserName: p.UserName,
		Password: PW,
		Email:    p.Email,
		Gender:   p.Gender,
	}}
	err := manager.RmqAddManagerDao()
	HttpResponse.ResponseSuccess(c, err)
}
